package com.hurl.waguji.web.cx;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.hurl.library.util.DateUtils;
import com.hurl.library.util.StringUtils;
import com.hurl.waguji.base.DateService;
import com.hurl.waguji.base.dao.HibernateDao;
import com.hurl.waguji.base.dao.HibernateService;
import com.hurl.waguji.persistence.SjPhfxBO;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 盘后分析
 * @author hurl
 *
 */
public class PhfxAction extends ActionSupport{
	private static final Logger log = Logger.getLogger(PhfxAction.class);
	private HibernateDao dao = HibernateService.getDao();
	private List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
	
	private String gplx;
	
	public String getGplx(){
		return StringUtils.isBlank(this.gplx)?"ALL":this.gplx;
	}
	public void setGplx(String gplx){
		this.gplx = gplx;
	}
	public List<Map<String,Object>> getList(){
		return this.list;
	}
	public void setList(List<Map<String,Object>> list){
		this.list = list;
	}
	
	public String execute() throws Exception{
		List<SjPhfxBO> list = dao.createCriteria(SjPhfxBO.class)
				.add(Restrictions.eq("id.gplx", this.getGplx()))
				.addOrder(Order.desc("id.rq"))
				.setFetchSize(10)
				.setReadOnly(true).list();
		
		if(list!=null && !list.isEmpty()){
			for(SjPhfxBO bo : list){
				Map<String,Object> map = new HashMap<String,Object>();
				map.put("rq", DateUtils.formatDate(bo.getId().getRq(), DateUtils.FORMAT_DATE_CN));
				map.put("gplx", bo.getId().getGplx());
				map.put("cjeTotal", StringUtils.formatChineseNumber(bo.getCjeTotal()));
				map.put("cjeMaxCje", StringUtils.formatChineseNumber(bo.getCjeMaxCje()));
				map.put("cjeMaxGpdm", bo.getCjeMaxGpdm());
				map.put("cjeMaxGpmc", bo.getCjeMaxGpmc());
				map.put("cjeMinCje", StringUtils.formatChineseNumber(bo.getCjeMinCje()));
				map.put("cjeMinGpdm", bo.getCjeMinGpdm());
				map.put("cjeMinGpmc", bo.getCjeMinGpmc());
				map.put("countZ", bo.getCountZ());
				map.put("countD", bo.getCountD());
				map.put("countP", bo.getCountP());
				map.put("countZz", bo.getCountZz());
				map.put("countDd", bo.getCountDd());
				map.put("countZt", bo.getCountZt());
				map.put("countDt", bo.getCountDt());
				
				this.list.add(map);
			}
		}
		return SUCCESS;
	}
}
